package cn.tedu.csmall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

/**
 * @author 何惠民
 */
@Slf4j
@Configuration
public class RedisConfiguration {

    public RedisConfiguration() {
        log.debug("创建配置类对象:RedisConfiguration");
    }


    /**
     * Serializable 序列化接口
     * */
    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(
            RedisConnectionFactory redisConnectionFactory){

        RedisTemplate<String,Serializable> redisTemplate = new RedisTemplate<>();

        //连接工程
        redisTemplate.setConnectionFactory(redisConnectionFactory);

        //设置Key序列化器
        redisTemplate.setKeySerializer(RedisSerializer.string());
        //设置Value序列化器
        redisTemplate.setValueSerializer(RedisSerializer.json());

        return redisTemplate;
    }


}
